<template>
  <a-card :bordered='false'>
    <!-- 查询区域 -->
    <div class='table-page-search-wrapper'>
      <a-form layout='inline' @keyup.enter.native='searchQuery'>
        <a-row :gutter='24'>

          <a-col :xl='3' :lg='7' :md='8' :sm='24'>
            <a-form-model-item label='年级' prop='queryParam.gradeId'>
              <!--              v-model="queryParam.gradeId"  对应java的Controller的接收参数vo对象的属性gradeId的值 -->
              <j-dict-select-tag @change='changeGradeId' v-model='queryParam.gradeId' placeholder='请选择年级'
                                 dictCode='cou_grade,grade_name,id,tenant_id  is not null order by  grade_order' />
            </a-form-model-item>
          </a-col>
          <!--          <a-col :span="6">选中值：{{ formData.gradeId}}</a-col>-->


          <a-col :xl='4' :lg='7' :md='8' :sm='24'>
            <a-form-model-item label='考试' prop='queryParam.examinationId'>
              <j-dict-select-tag @change='changeExaminationId' v-model='queryParam.examinationId' placeholder='请选择考试'
                                 :dictCode='queryParamSelect.examinationIdSelect' />
            </a-form-model-item>
          </a-col>


          <a-col :xl='3' :lg='7' :md='8' :sm='24'>
            <!--                <a-input placeholder="请输入科目" v-model="queryParam.subjectId"></a-input>-->
            <a-form-model-item label='班级' prop='queryParam.classId'>
              <!--                <j-select-multiple />   此处使用多选组件时，联动会失效，暂未解决联动失效问题-->
              <!--                <j-dict-select-tag />   单选正常联动，但无法多选查询-->
              <j-multi-select-tag v-model='queryParam.classId' placeholder='请选择班级'
                                  :dictCode='queryParamSelect.classIdSelect' />
            </a-form-model-item>
          </a-col>

          <a-col :xl='4' :lg='7' :md='8' :sm='24'>
            <a-form-item label='试卷'>
              <j-multi-select-tag @change='changeExaminationPaperId' v-model='queryParam.examinationPaperId'
                                  placeholder='请选择试卷' :dictCode='queryParamSelect.examinationPaperIdSelect' />
            </a-form-item>
          </a-col>

          <a-col :xl='4' :lg='7' :md='8' :sm='24'>
            <a-form-item label='学生姓名'>
              <a-input placeholder='请输入学生姓名' v-model='queryParam.studentName'></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl='4' :lg='7' :md='8' :sm='24'>
            <a-form-item label='导入批次'>
              <a-select
                v-model:value='queryParam.batchNumber'
                :options='batchNumbers'
              ></a-select>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :offset='8'>
            <span style='overflow: hidden;' class='table-page-search-submitButtons'>
              <a-button type='primary' @click='searchQuery' icon='search'>查询</a-button>
              <a-button type='primary' @click='searchReset' icon='reload' style='margin-left: 8px'>重置</a-button>
              <!--              <a @click="handleToggleSearch" style="margin-left: 8px">-->
              <!--                {{ toggleSearchStatus ? '收起' : '展开' }}-->
              <!--                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>-->
              <!--              </a>-->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class='table-operator'>
      <a-button @click='handleAdd' type='primary' icon='plus'>新增</a-button>
      <a-button type='primary' icon='download' @click="handleExportXls('ach_achievement_subject')">导出</a-button>
      <a-button type='primary' icon='save' @click='openModal'>{{ title }}</a-button>
      <a-upload name='file' :showUploadList='false' :multiple='false' :headers='tokenHeader'
                :action='importExcelUrl'
                @change='handleImportExcel'>
        <a-button type='primary' icon='import'>导入</a-button>
      </a-upload>
      <!-- 高级查询区域 -->
      <j-super-query :fieldList='superFieldList' ref='superQueryModal'
                     @handleSuperQuery='handleSuperQuery'></j-super-query>
      <a-dropdown v-if='selectedRowKeys.length > 0'>
        <a-menu slot='overlay'>
          <a-menu-item key='1' @click='batchDel'>
            <a-icon type='delete' />
            删除
          </a-menu-item>
        </a-menu>
        <a-button style='margin-left: 8px'> 批量操作
          <a-icon type='down' />
        </a-button>
      </a-dropdown>
      <template>
        <span style="float:right;">
          <a @click="searchQuery()"><a-icon type="sync" />刷新</a>
          <a-divider type="vertical" />
          <a-button v-print="'#datatable'" ghost type="primary">打印</a-button>
        </span>
      </template>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class='ant-alert ant-alert-info' style='margin-bottom: 16px;'>
        <i class='anticon anticon-info-circle ant-alert-icon'></i> 已选择 <a
        style='font-weight: 600'>{{ selectedRowKeys.length }}</a>项
        <a style='margin-left: 24px' @click='onClearSelected'>清空</a>
      </div>

      <a-table
        id="datatable"
        ref='table'
        size='middle'
        :scroll='{x:true}'
        bordered
        rowKey='id'
        :columns='columns'
        :dataSource='dataSource'
        :pagination='ipagination'
        :loading='loading'
        :rowSelection='{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}'
        class='j-table-force-nowrap'
        @change='handleTableChange'>

        <!--        <template slot='htmlSlot' slot-scope='text'>-->
        <!--          <div v-html='text'></div>-->
        <!--        </template>-->
        <!--        <template slot='imgSlot' slot-scope='text'>-->
        <!--          <span v-if='!text' style='font-size: 12px;font-style: italic;'>无图片</span>-->
        <!--          <img v-else :src='getImgView(text)' height='25px' alt=''-->
        <!--               style='max-width:80px;font-size: 12px;font-style: italic;' />-->
        <!--        </template>-->
        <!--        <template slot='fileSlot' slot-scope='text'>-->
        <!--          <span v-if='!text' style='font-size: 12px;font-style: italic;'>无文件</span>-->
        <!--          <a-button-->
        <!--            v-else-->
        <!--            :ghost='true'-->
        <!--            type='primary'-->
        <!--            icon='download'-->
        <!--            size='small'-->
        <!--            @click='downloadFile(text)'>-->
        <!--            下载-->
        <!--          </a-button>-->
        <!--        </template>-->

        <span slot='action' slot-scope='text, record'>
          <a @click='handleEdit(record)'>编辑</a>

          <a-divider type='vertical' />
          <a-dropdown>
            <a class='ant-dropdown-link'>更多 <a-icon type='down' /></a>
            <a-menu slot='overlay'>
              <a-menu-item>
                <a @click='handleDetail(record)'>详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title='确定删除吗?' @confirm='() => handleDelete(record.id)'>
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <ach-achievement-subject-modal ref='modalForm' @ok='modalFormOk'></ach-achievement-subject-modal>
    <JSelectClassExamination ref='modalClassExamination'
                             :title='this.title'
                             :isMulti='this.isMulti'
                             :msg='this.msg'
                             :exportXlsDemoUrl='this.exportXlsDemoUrl'
                             :isAll=this.isAll
    ></JSelectClassExamination>

  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import AchAchievementSubjectModal from './modules/AchAchievementSubjectModal'
import { downFile, getAction, putAction } from '@api/manage'
import JSelectClassExamination from '../components/modal/JSelectClassExamination'

export default {
  name: 'AchAchievementSubjectList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    AchAchievementSubjectModal,
    JSelectClassExamination
  },
  data() {
    return {
      description: 'ach_achievement_subject管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '学生',
          align: 'center',
          dataIndex: 'studentName'
        },
        {
          title: '科目',
          align: 'center',
          dataIndex: 'subjectName'
        },
        {
          title: '考试卷',
          align: 'center',
          dataIndex: 'examinationPaperName'
        },
        {
          title: '分数',
          align: 'center',
          dataIndex: 'achievementScore'
        },
        {
          title: '考试日期',
          align: 'center',
          dataIndex: 'achievementDate',
          customRender: function(text) {
            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },
        {
          title: '是否启用',
          align: 'center',
          dataIndex: 'izOpen_dictText'
        },
        {
          title: '所属部门',
          align: 'center',
          dataIndex: 'sysOrgName'
        },
        {
          title: '是否删除',
          align: 'center',
          dataIndex: 'delFlag_dictText'
        },
        {
          title: '创建人',
          align: 'center',
          dataIndex: 'createBy'
        },
        {
          title: '创建时间',
          align: 'center',
          dataIndex: 'createTime',
          customRender: function(text) {
            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
          }
        },
        // {
        //   title:'修改人',
        //   align:"center",
        //   dataIndex: 'updateBy'
        // },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        // list123: "/achachievementsubject/achAchievementSubject/list",
        list: '/achachievementsubject/achAchievementSubject/voList',
        delete: '/achachievementsubject/achAchievementSubject/delete',
        deleteBatch: '/achachievementsubject/achAchievementSubject/deleteBatch',
        listBatchNumber: '/achachievementsubject/achAchievementSubject/listBatchNumber',
        exportXlsUrl: '/achachievementsubject/achAchievementSubject/exportXls',
        importExcelUrl: 'achachievementsubject/achAchievementSubject/importExcelDemo'

      },
      //查询条件联动部分定义
      queryParamSelect: {
        // examinationIdSelect: 'ach_examination,examination_name,id,del_flag  =0 and iz_open  =1 and order by create_time  desc',
        // classIdSelect: 'cou_class,class_name,id,class_iz_open  =1 and class_iz_delete  = 0 order by  class_order',
        // examinationPaperIdSelect: 'ach_examination_paper aep,aep.examination_paper_name,aep.id,aep.iz_open =1 and aep.del_flag =0  order by examination_paper_name'
      },
      dictOptions: {},
      superFieldList: [],
      courseReleaseVisible: false,
      title: '科目成绩模板',
      msg: '您好，年级及考试为必填项。按照各自年级的考试进行选择(避免类似七年级选八年级的考试)。',
      exportXlsDemoUrl: '/achachievementsubject/achAchievementSubject/exportXlsDemo',
      isMulti: true,
      isAll: false,
      batchNumbers: []
    }
  },
  created() {
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  mounted() {
    this.initBatchNumber()
  },
  methods: {
    initDictConfig() {
    },
    initBatchNumber() {
      var params = {}//查询条件
      getAction(this.url.listBatchNumber, params).then((res) => {
        if (res.success) {
          res.result.forEach(item => {
            if (item.batchNumber) {
              let datas = {
                value: item.batchNumber,
                label: item.batchNumber
              }
              this.batchNumbers.push(datas)
            }
          })
        } else {
          this.$message.warning(res.message)
        }
      })
    },
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'studentId', text: '学生', dictCode: '' })
      fieldList.push({ type: 'string', value: 'subjectId', text: '科目', dictCode: '' })
      fieldList.push({ type: 'string', value: 'examinationPaperId', text: '考试卷', dictCode: '' })
      fieldList.push({ type: 'double', value: 'achievementScore', text: '分数', dictCode: '' })
      fieldList.push({ type: 'date', value: 'achievementDate', text: '考试日期' })
      fieldList.push({ type: 'int', value: 'izOpen', text: '是否启用(1是启用，0否停用)', dictCode: '' })
      fieldList.push({ type: 'string', value: 'sysOrgCode', text: '所属部门编码', dictCode: '' })
      fieldList.push({ type: 'string', value: 'tenantId', text: '学校id', dictCode: '' })
      fieldList.push({ type: 'int', value: 'delFlag', text: '0表示未删除,1表示删除', dictCode: '' })
      fieldList.push({ type: 'string', value: 'createBy', text: '创建人', dictCode: '' })
      fieldList.push({ type: 'date', value: 'createTime', text: '创建时间' })
      fieldList.push({ type: 'string', value: 'updateBy', text: '修改人', dictCode: '' })
      this.superFieldList = fieldList
    },
    openModal() {
      this.$refs.modalClassExamination.openModal()
    },
    //更改年级-->选择考试，选择班级
    changeGradeId() {
      if (this.queryParam.gradeId) { //判断不为空
        this.queryParamSelect.examinationIdSelect = 'ach_examination,examination_name,id,del_flag  =0 and iz_open  =1 and grade_id=\'' + this.queryParam.gradeId + '\' order by create_time  desc'
        this.queryParamSelect.classIdSelect = 'cou_class,class_name,id,class_iz_open  =1 and class_iz_delete  = 0 and grade_code=\'' + this.queryParam.gradeId + '\' order by  class_order'
      }
    },
    //更改考试-->选择试卷
    changeExaminationId() {
      if (this.queryParam.examinationId) {
        this.queryParamSelect.examinationPaperIdSelect = 'ach_examination_paper aep,aep.examination_paper_name,aep.id,aep.iz_open =1 and aep.del_flag =0 and aep.examination_id =\'' + this.queryParam.examinationId + '\'  order by aep.examination_paper_name'
      }
    },
    //更改试卷-->选择标准
    changeExaminationPaperId() {
      if (this.queryParam.examinationPaperId) {
        this.queryParamSelect.achievementStandardIdSelect = 'ach_achievement_standard aas inner join rel_ach_standard_distribution rasd on aas.id = rasd.achievement_standard_id,aas.achievement_standard_name,aas.id,aas.iz_open =1 and aas.del_flag =0 and rasd.paper_standard_effective =1 and  rasd.rel_obj_id=\'' + this.queryParam.examinationPaperId + '\''
      }
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>